﻿using System;
using System.Collections.Generic;

namespace SAE_Jam
{
    class BoxCollider
    {
        public delegate void CollisionEventHandler(BoxCollider other);
        public event CollisionEventHandler OnCollision;

        public int X;
        public int Y;
        public int Width;
        public int Height;

        public BoxCollider()
        {
            CollisionDetection.AddBoxCollider(this);
        }

        public BoxCollider(int x, int y, int width, int height)
        {
            this.X = x;
            this.Y = y;
            this.Width = width;
            this.Height = height;

            CollisionDetection.AddBoxCollider(this);
        }

        public void CheckCollision(BoxCollider other)
        {
            if (!(this.X + this.Width < other.X) || !(other.X + other.Width < this.X) || !(this.Y + this.Height < other.Y) || !(other.Y + other.Height < this.Y))
            {
                this.InvokeEvent(OnCollision);
            }
        }

        private void InvokeEvent(CollisionEventHandler handler)
        {
            if (handler != null)
            {
                handler(this);
            }
        }
    }
}
